package com.baidu.disk.webUtils;

import com.sun.imageio.plugins.common.ImageUtil;

import java.io.*;
import java.util.Date;
import java.util.UUID;

/**
 * Created by CJ on 2018-03-06.
 */
public class ImgeUtils {
    /**
     * 方法名：getSrcContent
     * 作者：zhouyh
     * 创建时间：2014-9-10 下午06:57:32
     * 描述：根据传入的url，调用phantomjs进行下载，并返回源码信息
     *
     * @param url
     * @return
     */
    public static String getSrcContent(String url) {
        //windows下phantomjs位置
        String path = "D:/Others/phantomjs-2.1.1-windows/bin/";
        Runtime rt = Runtime.getRuntime();
        Process process = null;
        try {
            process = rt.exec("D:" + File.separator + "Others" + File.separator + "phantomjs-2.1.1-windows" + File.separator + "bin" + File.separator + "phantomjs.exe D:" + File.separator + "Others" + File.separator + "phantomjs-2.1.1-windows" + File.separator + "bin" + File.separator + "a.js ");
        } catch (IOException e) {
            // TODO 这里写异常处理的代码
            e.printStackTrace();
        }
        InputStream is = process.getInputStream();
        BufferedReader br = new BufferedReader(new InputStreamReader(is));
        StringBuffer sbf = new StringBuffer();
        String tmp = "";
        try {
            while ((tmp = br.readLine()) != null) {
                sbf.append(tmp);
            }
        } catch (IOException e) {
            // TODO 这里写异常处理的代码
            e.printStackTrace();
        }

        return sbf.toString();
    }


    /**
     * 方法名：main
     * 作者：zhouyh
     * 创建时间：2014-9-10 下午04:19:46
     * 描述：TODO(这里用一句话描述这个方法的作用)
     *
     * @param args
     * @throws IOException
     */
   /* public static void main(String[] args) throws IOException, InterruptedException {
       *//* // TODO Auto-generated method stub
        String src = ImgeUtils.getSrcContent("http://weixin.sogou.com/gzh?openid=oIWsFt9MmzCvfJgaVxEUevPcuUCg");
        System.out.println(src);*//*
        String BLANK = "  ";
        String aa = "cmd.exe /c  D:"+ File.separator+"Others"+ File.separator+"phantomjs-2.1.1-windows"+File.separator+"bin"+File.separator+"phantomjs.exe" +BLANK
                +"D:"+ File.separator+"Others"+ File.separator+"phantomjs-2.1.1-windows"+File.separator+"bin"+File.separator+"a.js";



    }*/
    public static void main(String[] args) {
/*获取cmd命令*/
       /* try {
            Process pro = Runtime.getRuntime().exec("cmd /c D:\\Others\\phantomjs-2.1.1-windows\\bin\\phantomjs.exe  D:\\Others\\phantomjs-2.1.1-windows\\bin\\snapshot.js  'http://api.weibo.com/2/statuses/go?uid=1483330984&id=4189856835662743' a.png"); //添加要进行的命令，"cmd  /c calc"中calc代表要执行打开计算器，如何设置关机请自己查找cmd命令
            BufferedReader br = new BufferedReader(new InputStreamReader(pro.getInputStream(),"utf-8")); //虽然cmd命令可以直接输出，但是通过IO流技术可以保证对数据进行一个缓冲。
            String msg = null;
            while ((msg = br.readLine()) != null) {
                System.out.println(msg);
            }
            br.close();
        } catch (IOException exception) {
        }*/

       /* try {
            Process pro = Runtime.getRuntime().exec("cmd /c clct");
        } catch (IOException e) {
            e.printStackTrace();
        }
*/
        String endTime = String.format("%tF %1$tT", new Date());
        System.out.println(endTime);
    }
}